/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Panel;

/**
 *
 * @author Administrator
 */
import java.awt.*;
import javax.swing.*;

public class Demo extends JFrame {

    public Demo() {
        super("Title");
        NewPanel p = new NewPanel();
        this.getContentPane().add(p); //将冒嫉絁Frame
        this.setSize(596, 298);
        this.setLocationRelativeTo(null); //么翱局
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new Demo();
    }

    class NewPanel extends JPanel {

        public NewPanel() {
        }

        public void paintComponent(Graphics g) {
            int x = 0, y = 0;
            java.net.URL imgURL = getClass().getResource("1.jpg");

            ImageIcon icon = new ImageIcon(imgURL);
            g.drawImage(icon.getImage(), x, y, getSize().width, getSize().height, this);
            while (true) {
                g.drawImage(icon.getImage(), x, y, this);
                if (x > getSize().width && y > getSize().height) {
                    break;
                }
                if (x > getSize().width) {
                    x = 0;
                    y += icon.getIconHeight();
                } else {
                    x += icon.getIconWidth();
                }
            }
        }
    }
}
